﻿using System;
using System.Collections.Generic;

namespace PageAdmin.Utils.ORM
{
    /// <summary>
    /// 已经不建议的使用方法,仅仅为兼容性
    /// </summary>
    public static class ObsoleteMethod
    {

        #region 插入数据 历史方法
        /// <summary>
        /// 插入数据，当前方法已不建议使用
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="table"></param>
        /// <param name="fieldValueList"></param>
        /// <param name="returnNewId">是否获取最新插入的id</param>
        /// <returns></returns>
        [Obsolete]
        public static int Insert(this DataBaseContext dbContext, string table, IEnumerable<KeyValuePair<string, object>> fieldValueList,bool returnNewId = true)
        {
            DbKeyValueList dbKeyValueList = new DbKeyValueList();
            foreach(var keyValue in fieldValueList)
            {
                dbKeyValueList.Add(keyValue.Key, keyValue.Value);
            }
            return dbContext.Insert(table, dbKeyValueList, returnNewId);
        }

        #endregion

        #region 更新数据 历史方法

        /// <summary>
        /// 更新表中的多个字段，当前方法已不建议使用
        /// </summary>
        /// <param name="dbContext">DataBaseContext对象</param>
        /// <param name="table">表名</param>
        /// <param name="fieldDictionary"></param>
        /// <param name="sqlCondition">查询条件,不需要加where</param>
        /// <returns></returns>

        [Obsolete]
        public static int Update(this DataBaseContext dbContext, string table, IDictionary<string, dynamic> fieldDictionary, string sqlCondition)
        {
            DbKeyValueList dbKeyValueList = new DbKeyValueList();
            foreach (var keyValue in fieldDictionary)
            {
                dbKeyValueList.Add(keyValue.Key, keyValue.Value);
            }
            return dbContext.Update(table, dbKeyValueList, sqlCondition);
        }
        #endregion


    }
}
